package com.palfund.touchevent;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.RelativeLayout;

/**
 * Created by clvc on 2017/8/9.
 * 真正的速度是看不见的 !
 * Today is today , we will go !
 */

public class NormalView extends RelativeLayout {
    public NormalView(Context context) {
        super(context);
    }

    public NormalView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NormalView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * true     所有事件分发到当前view后不再分发,所有事件均由dispatchTouchEvent()处理
     * I/MainActivity: ---dispatchTouchEvent()--->0
     * I/BigView: ---dispatchTouchEvent()--->0
     * I/BigView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---dispatchTouchEvent()--->0
     * I/MainActivity: ---dispatchTouchEvent()--->1
     * I/BigView: ---dispatchTouchEvent()--->1
     * I/BigView: ---onInterceptTouchEvent()--->1
     * I/NormalView: ---dispatchTouchEvent()--->1
     */
    /**
     false      执行外层控件的onTouchEvent()
     I/MainActivity: ---dispatchTouchEvent()--->0
     I/BigView: ---dispatchTouchEvent()--->0
     I/BigView: ---onInterceptTouchEvent()--->0
     I/NormalView: ---dispatchTouchEvent()--->0
     I/BigView: ---onTouchEvent()--->0
     I/MainActivity: ---onTouchEvent()--->0
     */
    /**
     * super.dispatchTouchEvent(ev)
     * I/MainActivity: ---dispatchTouchEvent()--->0
     * I/BigView: ---dispatchTouchEvent()--->0
     * I/BigView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---dispatchTouchEvent()--->0
     * I/NormalView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---dispatchTouchEvent()--->0
     * I/SmallView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---onTouchEvent()--->0
     * I/NormalView: ---onTouchEvent()--->0
     * I/BigView: ---onTouchEvent()--->0
     * I/MainActivity: ---onTouchEvent()--->0
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.i("NormalView", "---dispatchTouchEvent()--->" + ev.getAction());
        return super.dispatchTouchEvent(ev);
    }

    /**
     * true     执行自己的onTouchEvent()
     * I/MainActivity: ---dispatchTouchEvent()--->0
     * I/BigView: ---dispatchTouchEvent()--->0
     * I/BigView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---dispatchTouchEvent()--->0
     * I/NormalView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---onTouchEvent()--->0
     * I/BigView: ---onTouchEvent()--->0
     * I/MainActivity: ---onTouchEvent()--->0
     */
    /**
     * false等同super.onInterceptTouchEvent(ev)
     * I/MainActivity: ---dispatchTouchEvent()--->0
     * I/BigView: ---dispatchTouchEvent()--->0
     * I/BigView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---dispatchTouchEvent()--->0
     * I/NormalView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---dispatchTouchEvent()--->0
     * I/SmallView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---onTouchEvent()--->0
     * I/NormalView: ---onTouchEvent()--->0
     * I/BigView: ---onTouchEvent()--->0
     * I/MainActivity: ---onTouchEvent()--->0
     */

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Log.i("NormalView", "---onInterceptTouchEvent()--->" + ev.getAction());
        return super.onInterceptTouchEvent(ev);
    }

    /**
     * true     消费后不再向上传递,以后所有事件dispatchTouchEvent()后直接onTouchEvent()消费
     * I/MainActivity: ---dispatchTouchEvent()--->0
     * I/BigView: ---dispatchTouchEvent()--->0
     * I/BigView: ---onInterceptTouchEvent()--->0
     * I/NormalView: ---dispatchTouchEvent()--->0
     * I/NormalView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---dispatchTouchEvent()--->0
     * I/SmallView: ---onInterceptTouchEvent()--->0
     * I/SmallView: ---onTouchEvent()--->0
     * I/NormalView: ---onTouchEvent()--->0
     * I/MainActivity: ---dispatchTouchEvent()--->1
     * I/BigView: ---dispatchTouchEvent()--->1
     * I/BigView: ---onInterceptTouchEvent()--->1
     * I/NormalView: ---dispatchTouchEvent()--->1
     * I/NormalView: ---onTouchEvent()--->1
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i("NormalView", "---onTouchEvent()--->" + event.getAction());
        return super.onTouchEvent(event);
    }
}
